{{ include("common/header.html")}}
<div class="layui-container fly-marginTop">
    <div class="fly-panel fly-panel-user" pad20>
        <div class="layui-tab layui-tab-brief" lay-filter="user">
            <ul class="layui-tab-title">
                <li><a href="{{G.url('app/login/index')}}">登入</a></li>
                <li class="layui-this">重置密码</li>
            </ul>
            <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                <div class="layui-tab-item layui-show">
                    {% if data['email'] %}
                    <div class="fly-msg">{{data['email']}}，请重置您的密码</div>
                    {% elseif data['mobile'] %}
                    <div class="fly-msg">{{data['mobile']}}，请重置您的密码</div>
                    {% endif %}

                    <div class="layui-form layui-form-pane"  style="margin-top: 30px;">
                        <form action="/user/repass" method="post">
                            <div class="layui-form-item">
                                <label for="L_pass" class="layui-form-label">密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="L_pass" name="password" required lay-verify="required" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">6到16个字符</div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_repass" class="layui-form-label">确认密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="L_repass" name="repass" required lay-verify="required" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_vercode" class="layui-form-label">验证码</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_vercode" name="vercode" required lay-verify="required"
                                           placeholder="请回答后面的验证码" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid" style="padding:0px 0!important;margin-top:-0.5px;">
                                    <img onclick="javascript:re_captcha();" src="{{ G.url('app/login/captcha') }}"
                                         alt="验证码" title="刷新图片" width="100" height="36"
                                         id="c2c98f0de5a04167a9e427d883690ff6" border="0">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                {% if data['email'] %}
                                <input type="hidden" name="email" value="{{data['email']}}">
                                {% elseif data['mobile'] %}
                                <input type="hidden" name="mobile" value="{{data['mobile']}}">
                                {% endif %}
                                <input type="hidden" name="token" value="{{data['token']}}">
                                <button class="layui-btn" lay-submit lay-filter="formDemo">提交</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    //Demo
    layui.use(['layer', 'form'], function () {
        var form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function (data) {
            var field = data.field;
            $.ajax({
                url: "{{G.url('app/login/resetpassword')}}",
                type: 'post',//请求的方式
                async: true,//是否异步  默认为异步
                data: field,//当前ajax请求的参数  
                dataType: "json",
                success: function (data) {//发送成功时的代码执行
                    if (data.code == 1001) {
                        layer.msg(data.data);

                        setTimeout(function(){
                            window.location.href="{{G.url('app/login/index')}}";
                        }, 1500);
                    }

                    if(data.code== 2001)
                    {
                        if(data.data.token){
                            layer.msg(data.data.token,{icon:5});
                        }else if(data.data.email) {
                            layer.msg(data.data.email, {icon: 5});
                        }else if(data.data.mobile) {
                                layer.msg(data.data.mobile,{icon:5});
                        }else if(data.data.repass) {
                            layer.msg(data.data.repass,{icon:5});
                        }else if(data.data.password)
                        {
                            layer.msg(data.data.password,{icon:5});
                        }else{
                            layer.msg(data.data,{icon:5});
                        }
                    }
                },
                error: function () {//失败时的代码执行
                    layer.msg("找回密码失败",{icon:5});
                    re_captcha();
                }

            });
            return false;
        });
    });


    /**
     * 刷新验证码
     */
    function re_captcha() {
        var url = "{{ G.url('app/login/captcha',{'captcha':'random'}) }}";
        var random = Math.random();
        url = url.replace("random", random);//使用js自带函数进行变量替换
        document.getElementById('c2c98f0de5a04167a9e427d883690ff6').src = url;
    }
</script>
{{ include("common/footer.html")}}